




layui.use('table', function () {
    //用table就要定义
    var table = layui.table;
    //用form就要定义
    var form = layui.form;
    //表格数据加载
    table.render({
        elem: '#test'
        , url: '/Login/GetMoudelList2/'
        , cellMinWidth: 80
        , cols: [[
            { type: 'checkbox' }
            , { field: 'Id', width: 50, align: 'center', title: 'ID', sort: true }
            , { field: 'TrainTitle', width: 190, align: 'center', title: '培训标题' }
            , { field: 'Speaker', width: 80, align: 'center', title: '主讲人' }
            , { field: 'StartTime', width: 160, align: 'center', title: '开始时间', templet: "<div>{{ Format(d.StartTime, 'yyyy-MM-dd hh:mm')}}</div>" }
            , { field: 'EndTime', width: 160, align: 'center', title: '结束时间', templet: "<div>{{ Format(d.EndTime, 'yyyy-MM-dd hh:mm')}}</div>" }
            , { field: 'UserId', width: 80, align: 'center', title: '用户ID' }
            , { field: 'Address', width: 180, align: 'center', title: '地址' }
            , { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
        ]]
        , page: true
        , id: 'test'
    });
    //监听工具
    table.on('tool(demo)', function (obj) {
        var AdminUser = obj.data;

        if (obj.event === 'del') {
            //删除
            layer.confirm('确定删除吗？', function (index) {
                $.ajax({
                    url: "/Login/DELETE",
                    type: "Post",
                    data: AdminUser,
                    success: function (operateResult) {
                        if (operateResult.Success) {
                            layer.msg('删除成功！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            }, function () {
                                location.reload();//刷新页面
                                layer.close(index);
                            });
                        }
                        else {
                            layer.msg('删除失败！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            });
                        }
                    }
                });
            });
        }
        else if (obj.event === 'edit') {

            window.location.href = "/Home/Train_tail?id=" + AdminUser.Id;
        };
    })
    //监听表格复选框选择
    table.on('checkbox(demo)', function (obj) {
    });
    //监听复选框，必须先定义美元符号在定义
    var $ = layui.$, active = {
        getCheckData: function () {
            //获取选中数据
            var checkStatus = table.checkStatus('test')
                , data = checkStatus.data;
            //获取拼接的id
            var id = BatchDelete(data);
            //删除数据
            layer.confirm('真的要删除吗', function (index) {
                $.ajax({
                    url: "/Login/BatchDelete?id=" + id,
                    type: "Post",
                    success: function (operateResult) {
                        if (operateResult.Success) {
                            layer.msg('删除成功！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            }, function () {
                                location.reload();//刷新页面
                                layer.close(index);
                            });
                        }
                        else {
                            layer.msg('删除失败！', {
                                title: '提示框',
                                icon: 1,
                                time: 2000
                            });
                        }
                    }
                });

            });
        }
    };
    //点击批量删除按钮事件
    $('#batchDelete').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    //多个条件查询
    $("#search").click(function () {
        //获取页面管理员名称和时间
        var title = $("#name").val();
        var speaker = $("#person").val();
        var date = $("#time1").val();

        //上述方法等价于
        table.reload('test', {
            //url: '/Login/GetMoudelList2?demo=' + demo
            where: { //设定异步数据接口的额外参数，任意设
                title: title,
                date: date,
                speaker: speaker,

            }
        });
    })

})
//拼接id
function BatchDelete(data) {
    var id = "";
    for (var i = 0; i < data.length; i++) {
        if (i != data.length - 1) {
            id += data[i].Id + ',';
        }
        else {
            id += data[i].Id;
        }
    }
    return id;
}











/**
 * Created by Administrator on 2016/8/4.
 */

var name, person, currentID, time, flag = true;
function Trainload() {
    $('#table').bootstrapTable({
        method: "get",
        striped: true,
        singleSelect: false,
        dataType: "json",
        pagination: true, //分页
        pageSize: 10,
        pageNumber: 1,
        search: false, //显示搜索框
        contentType: "application/x-www-form-urlencoded",
        queryParams: null,
        columns: [

            {
                checkbox: "true",
                field: 'ID',
                align: 'center',
                valign: 'middle'
            },
            {
                title: "编号",
                field: 'class',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '培训名称',
                field: 'sex',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '主讲人',
                field: 'type',
                align: 'center'
            },
            {
                title: '开始时间',
                field: 'name',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '结束时间',
                field: 'name',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '参加人',
                field: 'name',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '培训地点',
                field: 'name',
                align: 'center',
                valign: 'middle'
            },
            {
                title: '成绩',
                field: 'work',
                align: 'center'
            },

            {
                title: '操作',
                field: '',
                align: 'center',
                formatter: function (value, row) {
                    var e = '<button button="#" mce_href="#" onclick="edit(\'' + row.WORKRECORDID + '\')">查看详情</button> '

                    return e;
                }
            }
        ]
    });
    getData();
}
function getData() {
    if (flag) {
        name = "";
        person = "";
        time = "";
        flag = false;
    } else {
        person = $("#person").val();
        name = $("#name").val();
        time = $("#demo").val();
    }
    $.ajax({
        type: "GET",
        url: "../WorkRecord/SearchWork?dtStart=" + person + "&dtEnd=" + type + "&dtEnd=" + time,
        dataType: "json",
        success: function (result) {
            if (result.data) {
                var TableData = result.data;
                $('#table').bootstrapTable("load", TableData);
            }
        }
    })
}
//初始化状态下拉菜单
function getType() {
    $.ajax({
        url: '../Common/GetPhaseList',
        type: 'GET',
        dataType: 'json',
        success: function (data) {
            var PHASEValue = data.data;
            if (PHASEValue.length > 0) {
                $("#part").html("");
                for (var i = 0; i < PHASEValue.length; i++) {
                    if (TASKPHASE == PHASEValue[i].ID) {
                        var html = "<Option value = '" + PHASEValue[i].ID + "'  selected = 'true'>" + PHASEValue[i].NAME + "</Option>";
                    } else {
                        var html = "<Option value = '" + PHASEValue[i].ID + "'>" + PHASEValue[i].NAME + "</Option>";
                    };
                    $("#part").append(html);
                }
            }


        },
        error: function (err) {
        }

    })
}
function add() {
    openlayer()
    currentID = "";
}
function edit(id) {
    openlayer()
    currentID = id;
}
function out(id) {
    alert(id)
    var Id = id;
    $.ajax({
        url: '../WorkRecord/DeleteWork?workId=' + Id,
        type: 'GET',
        dataType: 'json',
        success: function (data) {
            if (data.data) {
                alert("导出成功！")
                // getData();
            } else {
                alert("导出失败")
            }
        },
        error: function (err) {
        }
    });
}
function getCurrentID() {
    return currentID;
}
function openlayer(id) {
    layer.open({
        type: 2,
        title: '添加信息',
        shadeClose: true,
        shade: 0.5,
        skin: 'layui-layer-rim',
        //            maxmin: true,
        closeBtn: 1,
        area: ['90%', '98%'],
        shadeClose: true,
        closeBtn: 1,
        content: 'train_tail01.html'
        //iframe的url
    });
}





